package com.daiyang.blog.controller;

import com.daiyang.blog.common.result.Result;
import com.daiyang.blog.service.DTO.UserInfoResponse;
import com.daiyang.blog.service.DTO.UserLoginResponse;
import com.daiyang.blog.service.DTO.UserInfoParam;
import com.daiyang.blog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;


    @RequestMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserInfoParam user) {
        log.info("login User:{}", user);
        return userService.login(user);
    }


    @RequestMapping("getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull Integer userId) {
        return userService.getUserInfo(userId);
    }
    @RequestMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull Integer blogId){
        return userService.selectAuthorInfoByBlogId(blogId);
    }

}
